package com.zd.mock.zhangxuanshuo;

import com.github.javafaker.Faker;
import com.zd.jdbc.ShoppingStoreDAOImpl;
import com.zd.bean.ShoppingStore;
import com.zd.jdbc.ShoppingStoreDAO;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

public class ShoppingStoreGenerator {
    public static void main(String[] args) {
        Faker faker = new Faker(new Locale("zh-CN"));
        ShoppingStoreDAO storeDAO = new ShoppingStoreDAOImpl();

        // 获取已存在的店铺ID（1-6）
        List<Integer> existingIds = storeDAO.getAllStoreIds();
        int startId = existingIds.isEmpty() ? 1 : existingIds.size() + 1;

        // 郑州行政区
        String[] regions = {"中原区", "二七区", "金水区", "惠济区", "管城回族区", "郑东新区", "高新区"};

        // 店铺类别
        String[] categories = {
                "特产店", "纪念品店", "手工艺品店", "茶叶店", "丝绸店",
                "陶瓷店", "药妆店", "美食广场", "文创商店", "免税店"
        };

        // 生成100个店铺
        for (int i = startId; i < startId + 100; i++) {
            String region = faker.options().option(regions);

            ShoppingStore store = ShoppingStore.builder()
                    .storeName(faker.company().name() + "购物中心")
                    .regionName(region)
                    .category(faker.options().option(categories))
                    .address("河南省郑州市" + region + faker.address().streetAddress()) // 生成符合实际的地址
                    .contactPhone("0371-" + faker.phoneNumber().subscriberNumber(8)) // 生成郑州区号电话
                    .status(faker.random().nextInt(0, 1))
                    .createTime(faker.date().past(365, TimeUnit.DAYS)
                            .toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime())
                    .updateTime(LocalDateTime.now())
                    .build();

            storeDAO.insert(store);
            System.out.printf("生成店铺 [ID:%d]: %s | 区域: %s | 地址: %s%n",
                    i, store.getStoreName(), region, store.getAddress());
        }
        System.out.println("购物商店数据生成完成！共生成100个店铺");
    }
}